import socket

# 创建一个TCP套接字
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 服务器地址和端口
server_address = ('localhost', 12345)

# 连接到服务器
client_socket.connect(server_address)

try:
    # 发送消息到服务器
    message = '你好，服务器！'
    client_socket.sendall(message.encode('utf-8'))

    # 接收服务器响应
    data = client_socket.recv(1024)
    response = data.decode('utf-8')
    print(f'收到服务器响应: {response}')
finally:
    # 关闭套接字
    client_socket.close()